import 'package:xm_app/common/config/Address.dart';
import 'package:xm_app/common/http/api_response.dart';
import 'package:xm_app/common/http/http_utils.dart';
import 'package:xm_app/dao/DaoBase.dart';
import 'package:xm_app/model/GankCategoryList.dart';

class GankDao extends DaoBase {
  static GankDao _instance = GankDao._internal();

  factory GankDao() => _instance;
  GankDao._internal();

  ///https://gank.io/api/v2/hot/<hot_type>/category/<category>/count/<count>
  /// 请求方式: GET
  /// 注:
  ///
  /// hot_type 可接受参数 views（浏览数） | likes（点赞数） | comments（评论数）❌
  /// category 可接受参数 Article | GanHuo | Girl
  /// count: [1, 20]
  Future<ApiResponse> getHotCategory(int count) {
    return vipInvoke<GankCategoryListData>(
      () => HttpUtils.get(Address.hotCategoryApi(hotType: "views", category: "Girl", count: count)),
      creator: (jsonData) => GankCategoryListData.fromJson(jsonData),
    );
  }

  //https://gank.io/api/v2/data/category/<category>/type/<type>/page/<page>/count/<count>
  // 请求方式: GET
  // 注:
  //
  // category 可接受参数 All(所有分类) | Article | GanHuo | Girl
  // type 可接受参数 All(全部类型) | Android | iOS | Flutter | Girl ...，即分类API返回的类型数据
  // count: [10, 50]
  // page: >=1
  Future<ApiResponse> getCategory(int count, int page) {
    return vipInvoke<GankCategoryListData>(
      () => HttpUtils.get(Address.categoryApi(type: "Girl", category: "Girl", count: count, page: page)),
      creator: (jsonData) => GankCategoryListData.fromJson(jsonData),
    );
  }
}
